<template>
  <div>
    <el-form ref="form" :model="goBackToDrawer" label-width="80px" :disabled="this.isChangeable">
      <el-form-item label="工号">
        <el-input placeholder="请输入工号" v-model="goBackToDrawer.userName"></el-input>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input placeholder="请输入姓名" v-model="goBackToDrawer.realName"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input placeholder="请输入密码" v-model="goBackToDrawer.passWord"></el-input>
      </el-form-item>
      <el-form-item label="重复输入密码">
        <el-input placeholder="请重复输入密码" v-model="goBackToDrawer.passWord"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input placeholder="请输入手机号" v-model="goBackToDrawer.phone"></el-input>
      </el-form-item>
      <el-form-item label="电子邮箱">
        <el-input placeholder="请输入电子邮箱" v-model="goBackToDrawer.email"></el-input>
      </el-form-item>
      <el-form-item label="出生日期">
        <el-date-picker
          v-model="goBackToDrawer.birthday"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="出生日期">
        <el-date-picker
          v-model="goBackToDrawer.birthday"
          align="right"
          type="date"
          placeholder="选择日期"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="上传头像">
        <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload">
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
  export default {
    name: 'DataForm',
    data() {
      return {
        disabled: false,
        // formData: {
        //   userName: '',
        //   realName: '',
        //   phone: '',
        //   birthday: '',
        //   email: '',
        // }
        goBackToDrawer:this.sendOneToForm,
        imageUrl: ''

      }
    },
    methods: {
      onSubmit() {
        console.log('submit!');
      },
      selectDepart(){

      },
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      }
    },

    props:{
      sendOneToForm:{
        type: Object,
        default : null,
        required: false
      },
      isChangeable:{
        type:Boolean,
        default: true,
        required: true
      }
    }
  }
</script>

<style scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
